package com.cman777.springc.web.util;

import org.springframework.util.CollectionUtils;

import java.util.Map;

/**
 * @author chenzhicong
 * @time 2020/12/2 17:08
 */
public class UrlUtil {

    public static String packageUriAndParam(String uri, Map<String,Object> paramsMap){
        StringBuffer urlStringBuffer = new StringBuffer(uri);
        if (!CollectionUtils.isEmpty(paramsMap)) {
            urlStringBuffer.append("?");
            int index = 0;
            for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
                if (index == 0) {
                    urlStringBuffer.append(entry.getKey()).append("=").append(entry.getValue());
                } else {
                    urlStringBuffer.append("&").append(entry.getKey()).append("=").append(entry.getValue());
                }
                index++;
            }
        }
        return urlStringBuffer.toString();
    }
}
